﻿@using SCMS.Resource
@model SCMS.UI.Models.SalaryPayment
<br />

<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>--@Resources.Global_String_NewSPM--</h3>
    </div>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center">
                @Resources.SalaryPayment_String_PayrollMonth
            </th>
            <th align="center">
                @Resources.SalaryPayment_String_PayrollYear
            </th>
            <th align="center">
                @Resources.Global_String_Date
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntitySalaryP.PayrollMonth
            </td>
            <td align="center">
                @Model.EntitySalaryP.PayrollYear
            </td>
            <td align="center">
                @Model.EntitySalaryP.PayrollDate.Value.ToString("dd/MM/yyyy")
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                @Resources.Global_String_Office
            </th>
            <th align="center">
                @Resources.Global_String_Currency
            </th>
            <th align="center">
                @Resources.SalaryPayment_String_TotalPayrollPayment
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntitySalaryP.CountrySubOffice.Name
            </td>
            <td align="center">
                @Model.EntitySalaryP.Currency.ShortName
            </td>
            <td align="center">
                <b>@Model.EntitySalaryP.TotalPayroll.ToString("##,##0.00")</b>
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_SubjectPurpose:
            </td>
            <td colspan="2">
                @Model.EntitySalaryP.Subject
            </td>
        </tr>
    </table>
    <br />
    &nbsp;&nbsp;&nbsp;
    @Ajax.ActionLink(Resources.OrderRequest_AddNewItem4OR_AddNewItem, "LoadSalaryPItem", new { id = Model.EntitySalaryP.Id + "~" + Model.EntitySalaryP.SalaryCurrencyId }, new AjaxOptions
    {
        OnBegin = string.Format("ShowDialogue('{0}')", Resources.SalaryPayment_SalarPItemsList_CreatePayrollItem),
        UpdateTargetId = "popup-page",
        LoadingElementId = "popup-loading",
        Url = Url.Action("LoadSalaryPItem/" + Model.EntitySalaryP.Id + "~" + Model.EntitySalaryP.SalaryCurrencyId),
        OnSuccess = "CenterPopup();ClearForm();"
    })
    <br />
    @if (Model.SalaryPaymentItems!=null && Model.SalaryPaymentItems.Count() > 0)
    {
        <table width="98%" align="center" class="cardTable" cellspacing="0" cellpadding="0"
            border="1">
            <tr class="gridheader">
                <th colspan="5">
                    @Resources.Global_String_PayrollItems
                </th>
            </tr>
            <tr class="gridheader">
                <th>
                    @Resources.Global_String_ItemName
                </th>
                <th>
                    @Resources.Budget_CategoryList_ProjectNo
                </th>
                <th>
                    @Resources.Budget_CreateSubLine_LineNumber
                </th>
                <th>
                    @Resources.Global_String_Amount
                </th>
                 <th>
                    Manage
                </th>
            </tr>
            @foreach (var item in Model.SalaryPaymentItems)
            {
                <tr class="gridodd">
                    <td>
                        @item.EntitySalaryPBL.PayrollItem.Name
                    </td>
                    <td align="center">
                        @item.EntitySalaryPBL.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber
                    </td>
                    <td align="center">
                        @item.EntitySalaryPBL.ProjectBudget.LineNumber
                    </td>
                    <td align="right">
                        @item.EntitySalaryPBL.Amount.ToString("##,##0.00")
                    </td>
                    <td align="center">
                        @Ajax.ActionLink(Resources.Global_String_Edit, "Index", new { id = "EditSalaryBL" }, new AjaxOptions
                        {
                            OnBegin = "ShowDialogue('" + Resources.Global_String_Edit + " :: " + item.EntitySalaryPBL.PayrollItem.Name + "')",
                            UpdateTargetId = "popup-page",
                            LoadingElementId = "popup-loading",
                            Url = Url.Action("EditSalaryBL/" + item.EntitySalaryPBL.Id),
                            OnSuccess = "CenterPopup"
                        })
                        &nbsp;|&nbsp;
                        @Ajax.ActionLink(Resources.Global_String_Delete, "DeleteBL", new { blId = item.EntitySalaryPBL.Id, spmId = item.EntitySalaryPBL.SalaryId }, new AjaxOptions
                        {
                            UpdateTargetId = "SPtDiv",
                            LoadingElementId = "loading",
                            Confirm = string.Format(Resources.Global_String_ConfirmDelete, item.EntitySalaryPBL.PayrollItem.Name)
                        })
                    </td>
                </tr>
            }
        </table>
    }
    @if (Model.BudgetCheckResults != null && Model.BudgetCheckResults.Count > 0)
    {
        <br />
        <center style="text-align: center; color: Red; font-weight: bold; font-style: italic;">@Resources_frank.SalaryPayment_String_FundsUnavailableMessage</center>
        <table align="center" class="cardTable">
            <tr>
                <th>@Resources.Budget_CategoryList_ProjectNo</th>
                <th>@Resources.Budget_CreateSubLine_LineNumber</th>
                <th>@Resources.MasterBudget_MasterBudget_FundsAvailable</th>
                <th>@Resources_frank.SalaryPayment_String_SPMAmount</th>
            </tr>
            @foreach (var bcr in Model.BudgetCheckResults)
            {
                <tr>
                    <td>@bcr.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber</td>
                    <td>@bcr.ProjectBudget.LineNumber @bcr.ProjectBudget.Description</td>
                    <td style="color: Red; font-weight: bold;" align="right">@bcr.AvailableAmount.ToString("#,##0.00")</td>
                    <td align="right">@bcr.AmountChecked.ToString("#,##0.00")</td>
                </tr>
            }
        </table>
    }
    <br />
    <table width="98%" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td width="50%">
                <input type="button" class="btn green" value="  @Resources.Global_String_Back  " onclick="sendRequest('EditSPM/@Model.EntitySalaryP.Id', 'SPtDiv', 'loading');" />
            </td>
            <td width="50%" align="right">
                @if (Model.SalaryPaymentItems != null && Model.SalaryPaymentItems.Count() > 0)
                {
                    <input type="button" class="btn green" value="  @Resources.Global_String_SubmitForReview  " onclick="if(confirm('@Resources.Global_String_SubmitForReview?')){ sendRequest('SubmitSPM/@Model.EntitySalaryP.Id', 'SPtDiv', 'loading'); if (document.getElementById('table') != null) {initSorter();sorter.size(50);}}" />
                }
            </td>
        </tr>
    </table>
    <input type="hidden" id="actionStatus" value="@ViewBag.Response" />
    <input type="hidden" id="statusMsg" value="@ViewBag.msg" />
    <br />
    
    <br />
</div>
